package com.zscg.sequence.ui;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import com.zgcs.sequence.tool.ServiceTool;

public abstract class SequenceActivity extends Activity {

	BroadcastReceiver broadCast;
	IntentFilter intentFilter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		registBroadCase();
	}

	protected void registBroadCase() {
		intentFilter = new IntentFilter(ServiceTool.ORDER_UL);
		addselfFilter();
		broadCast = new SequenceBroadcastReceiver();
		registerReceiver(broadCast, intentFilter);
	}

	/**
	 * 添加属于自己在监听
	 */
	protected abstract void addselfFilter();

	/**
	 * 处理自己在广播
	 * 
	 * @param context
	 * @param intent
	 */
	protected abstract void disposeSelf(Context context, Intent intent);

	/**
	 * 处理登录成功
	 */
	protected abstract void disposeLogin(Intent intent);

	class SequenceBroadcastReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			if (ServiceTool.ORDER_UL.equals(intent.getAction())) {
				disposeLogin(intent);
			} else {
				disposeSelf(context, intent);
			}
		}

	}

	@Override
	public void finish() {
		unregisterReceiver(broadCast);
		super.finish();
	}

}